
'use strict';

app.controller('cartCtrl', function ($scope) {
    // 外部数据源： db、cache
    var fakeShopList = [  
       {
            "name":"小炒肉",
            "img":"assets/images/img-1.jpg",
            "price":7.79,
            "number":1
       },
       {
            "name":"Special Coffee",
            "img":"assets/images/img-2.jpg",
            "price":7.79,
            "number":2
       } 
    ];
    $scope.shopList = fakeShopList;

    $scope.checkoutShop=function(shop){  
        // var shop_list_data = shop;
        $scope.shopList = shop;
        // debugger;
       // console.log(shop);
        // console.log(shop_list_data);
       // $state.go('app.checkOut', shop); 
        // $rootScope.$broadcast('to_checkout', shop_list_data);
    };
    // $scope.$on('to_checkout', function(event,data) {  
    //     // console.log(data);//子级能得到值
    //     debugger;
    //     console.log($rootScope.shop_list_data);
    //     $scope.checkoutshop = data;
    //     console.log($scope.checkoutshop);
    // });


    // 购物车移除一项
    $Scope.removeShop=function(index){  
        if(confirm('确定移除此项吗？')){  
            $rootScope.shopList.splice(index,1);  
        } 
    };
    
});